package com.itgacl.magic4j.libcommon.component.ws;

import com.itgacl.magic4j.libcommon.bean.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@ConditionalOnProperty(prefix = "ws", value = "enable", havingValue = "true")
@Api(tags = "websocket消息推送")
@RestController
@RequestMapping("/ws/api")
public class WsPushController {

    @Autowired
    private WsService wsService;

    @ApiOperation("推送消息到客户端")
    @PostMapping("/pushWsMsg")
    public R<Void> pushWsMsg(String clientId,String msg) throws IOException {
        wsService.sendMsg(clientId,msg);
        return R.ok();
    }
}
